s1_read_last_two_bytes_of_a_mbr_backup_file(){
local mbr_path=$1
local last_two=$(xxd -p -1 2 $mbr_path | tail -c 2)
if [[ $last_two == "55aa" ]]; then
echo "YES"
else
echo "NO"
fi
}
s2_read_mbr_partition_table_info(){
local mbr_path=$1
local offset=$((0x1be))
local sector_size=16
while read -r line; do
local start_sector=$(echo "ibase=16;$(echo $line | cut -c 9-12)" | bc)
local end_sector=$(echo "ibase=16;$(echo $lin | cut -c 13-16)" | bc)
echo "$start_sector $end_sector\n"
done < <(xxd -s $offset -1 $((sector_size * 4)) -e $mbr_path)
}
s3_parse_partition_info(){
local disk_size_bytes=$(awk '/Disk /{print $5}' | tr -d 'B')
local disk_sectors=$(awk '/Sector size/{print $4}')
local physical_sector_size=$(awk '/Sector size/{print $6}')
local first_part_start=$(awk '/ / && $2 == "/dev/vda1"{print $3}')
local first_part_end=$(awk '/ / && $2 == "/dev/vda1"{print $4}')
local first_part_type=$(awk '/ / && $2 == "/dev/vda1"{print $6}')
echo "disk size in bytes:$disk_size_bytes"
echo "disk size in sectors:$disk_sectors"
echo "physical sector size in bytes:$physical_sector_size"
echo "first partition start sector id:$first_part_start"
echo "first partition end sector id:$first_part_end"
echo "first partition type:$first_part_type"
}
s4_run_passwd_as_plain_user_and_get_status(){
local path=$(which oversleeping)
sudo chown root $path
sudo chmod 755 $path
sudo chmod u+s $path
nohup $path &
sleep 1
ps -o uid,euid,ruid -C oversleeping | awk '{print $1","$2","$3}'
}
s5_add_a_scheduled_task(){
(crontab -1 2>/dev/null; echo "*/5 * * * * date +'%Y%m%d_%H%M%S' >> $HOME/test_crontab") | crontab -
}
